#ifndef __BLOCKQUEUE_H
#define __BLOCKQUEUE_H

#include <mutex>
#include <deque>
#include <condition_variable>

template<typename T>
class BlockDeque{
	explicit BlockDeque(size_t max_capacity = 1000);
	~BlockDeque();
	bool empty();
	bool full();
	size_t size();
	size_t capacity();
	void push_back(const T &);
	void push_front(const T &);
	bool pop(T & item);
	bool pop(T & item, int timeout);
	T back();
	T front();
	void flush();
	void clear();
private:
	size_t m_capacity;
	std::mutex m_mutex;
	std::deque<T> m_deque;
	bool isClose;
	std::condition_variable m_cond_producer;
	std::condition_variable m_cond_consumer;
};
template<typename T>
BlockDeque<T>::BlockDeque(size_t max_capacity):m_capacity(max_capacity){
	isClose = false;
}

template<typename T>
void BlockDeque<T>::push_front(const T & item){
	std::unique_lock<std::mutex> lock(m_mutex);
	while(m_deque.size >= m_capacity){
		m_cond_producer.wait();
	}
	m_deque.push_back(item);
	m_cond_consumer.notify_one();
}



#endif